home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cbibcode.arc / FREE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-05  |  499 b   |  20 lines

  1. /* free.c --- p. 136 */
  2. # include <stdio.h>
  3. # include <stdlib.h>
  4. # include <alloc.h>
  5. # define MAX_CHR 80
  6. main()
  7. {
  8.     char *buffer;
  9.             /* Allocate room for string and check for NULL */
  10.     if( (buffer = (char *)malloc(MAX_CHR)) == NULL)
  11.     {
  12.         printf("Allocation Failed.\n");
  13.         exit(0);
  14.     }
  15.     printf("Buffer allocated. Enter string to store: ");
  16.     gets(buffer);
  17.     printf("\nYou entered: %s\n", buffer);
  18.     free((void *)buffer);            /* Deallocate the memory */
  19.     printf("Buffer deallocated.\n");
  20. }